/**
 * Created by Intellij IDEA
 *
 * @author 王俊凯
 * @Date: 2023/2/27 10:14
 * @Version 1.0
 */
package com.eight.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.eight.dao.CarInformationDao;
import com.eight.pojo.TbCar;
import com.eight.service.CarInformationService;
import com.eight.vo.CarVo;
import com.eight.vo.ComResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarInformationServiceImpl implements CarInformationService {

    @Autowired
    private CarInformationDao carInformationDao;


    @Override
    public ComResult selectAllCar(CarVo carVo) {
        PageHelper.startPage(carVo.getPageNum(), carVo.getPageSize());
        QueryWrapper<TbCar> wrapper =null;
        if (carVo.getName()!=null){
            wrapper = new QueryWrapper<>();
            wrapper.like("carName",carVo.getName());
        }

        List<TbCar> tbCarList = carInformationDao.selectAllCar(carVo.getName());

        PageInfo<TbCar> info = new PageInfo<>(tbCarList);
        return new ComResult(2000,"查询成功",info);
    }


    @Override
    public ComResult insertCar(TbCar tbCar) {
        int insert = carInformationDao.insert(tbCar);
        return new ComResult(2000,"添加车辆",insert);
    }

    @Override
    public ComResult deleteCar(int id) {
        int delete = carInformationDao.deleteById(id);
        return new ComResult(2000,"删除车辆",delete);
    }

    @Override
    public ComResult updateCar(TbCar tbCar) {
        int update = carInformationDao.updateById(tbCar);
        return new ComResult(2000,"修改车辆",update);
    }

    /**
     * 查询车辆的类型和门店
     * @param shopId
     * @param type
     * @return
     */
    @Override
    public List<TbCar> selectByTypeShopId(Integer shopId, Integer type) {
        return carInformationDao.selectCarLits(shopId,type);
    }



    /**
     * 根据价格排序
     * @param shopId
     * @param type
     * @param orderBy
     * @return
     */
    @Override
    public List<TbCar> selectShopByType(Integer shopId, Integer type, Integer orderBy) {
        List<TbCar> cars = carInformationDao.selectShopByType(shopId, type, orderBy);
        return cars;
    }

    /**
     * 修改车辆的状态
     * @param id 车辆的id
     * @return 返回修改结果
     */
    @Override
    public int updateCarById(Integer id) {
        TbCar tbCar = new TbCar();
        tbCar.setId(id);
        tbCar.setState(0);
        return carInformationDao.updateById(tbCar);
    }
}